package com.contactmgr.listadapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.contactmgr.R;
import com.contactmgr.logObjects.CallDataLog;
import com.contactmgr.utils.DateUtils;

public class CallListAdapter extends ArrayAdapter<CallDataLog> {
	private List<CallDataLog> callL;
	int resourceid;
	Context context;

	public CallListAdapter(Context context, int textViewResourceId, List<CallDataLog> callL) {
		super(context, textViewResourceId, callL);
		this.context = context;
		this.callL = callL;
		this.resourceid = textViewResourceId;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup viewGroup) {
		CallDataLog call = callL.get(position);
		if (null == convertView) {
			// inflate xml layout
			LayoutInflater inflator = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflator.inflate(resourceid, null);

		}
		TextView numberNameTv = (TextView) convertView.findViewById(R.id.callfromToNameNumber);
		TextView dateCallTv = (TextView) convertView.findViewById(R.id.dateCall);
		TextView callDurTv =  (TextView) convertView.findViewById(R.id.callDuration);
		numberNameTv.setText(call.getNumber() + "  " + call.getName());
		dateCallTv.setText("Date :"+DateUtils.getFormattedDateOfEpoch(call.getDate()));
		callDurTv.setText("Duration :"+DateUtils.getFormattedDuration(call.getDuration()));
		return convertView;
	}

}
